package ma.ac.onousc.gestionfi.budget.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import ma.ac.onousc.gestionfi.EngagementPaiement.model.Engagement;

/**
 * The persistent class for the rubrique_budgetaire database table.
 * 
 */
@Entity
@Table(name = "rubrique_budgetaire")
@NamedQueries({
		@NamedQuery(name = "RubriqueBudgetaire.findAll", query = "select rb from RubriqueBudgetaire rb join rb.rubrique r join r.typeBudget t"),
		@NamedQuery(name = "RubriqueBudgetaire.findByTypeBudgetAndAnnee", query = "select rb from RubriqueBudgetaire rb join rb.rubrique r join rb.programmeEmploi pe where r.typeBudget.idTypeBudget=:TYPE_BUDGET and pe.anneeProgrammeEmploi = :ANNEE"),
		@NamedQuery(name = "RubriqueBudgetaire.findByProgrammeEmploiAndEtablissement", query = "select rb from RubriqueBudgetaire rb join rb.rubrique r join rb.programmeEmploi pe join r.typeBudget t where pe.idProgrammeEmploi = :PROGRAMME_EMPLOI and ((rb.etablissement.idEtablissement is not NULL and rb.etablissement.idEtablissement = :ETABLISSEMENT and rb.etablissement is NOT NULL) or (:ETABLISSEMENT is NULL and rb.etablissement is NULL))"),
		@NamedQuery(name = "RubriqueBudgetaire.findSUMByTypeBudgetAndAnnee", query = "select rb, sum(rb.creditAccordeRubriqueBudgetaire) from RubriqueBudgetaire rb join rb.rubrique r join rb.programmeEmploi pe join rb.etablissement e where r.typeBudget.idTypeBudget=:TYPE_BUDGET and pe.anneeProgrammeEmploi = :ANNEE and e.etablissement is not null group by r.idRubrique"),
		@NamedQuery(name = "RubriqueBudgetaire.findByEtabAndAnnee", query = "select rb from RubriqueBudgetaire rb join rb.rubrique r where ((rb.etablissement.idEtablissement = :IdETAB and :IdETAB <> null) or (rb.etablissement.idEtablissement = null and :IdETAB = null)) and rb.programmeEmploi.anneeProgrammeEmploi = :ANNEE and rb.rubrique.typeBudget.idTypeBudget=:TYPE_BUDGET"),
		@NamedQuery(name = "RubriqueBudgetaire.findByEtabAndAnneeAndRubrique", query = "select rb from RubriqueBudgetaire rb where rb.etablissement.idEtablissement =:idEtab and rb.programmeEmploi.idProgrammeEmploi =:idProemp and rb.rubrique.idRubrique =:idRubrique") })

public class RubriqueBudgetaire implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID_RUBRIQUE_BUDGETAIRE")
	private int idRubriqueBudgetaire;

	@Column(name = "CREDIT_ACCORDE_RUBRIQUE_BUDGETAIRE")
	private BigDecimal creditAccordeRubriqueBudgetaire;
	
	private BigDecimal creditEngagement;
	private BigDecimal creditPaiement;

	@Column(name = "CREDIT_FINAL_RUBRIQUE_BUDGETAIRE")
	private BigDecimal creditFinalRubriqueBudgetaire;

	@Column(name = "CREDIT_REPORTE_RUBRIQUE_BUDGETAIRE")
	private BigDecimal creditReporteRubriqueBudgetaire;
	
	@Column(name = "CREDIT_ENG_BUDGET_INVEST")
	private BigDecimal creditEngagementBudgetInvest;

	// bi-directional many-to-one association to OrdreModif
	@OneToMany(mappedBy="rubBudg")
	private Set<OrdreModif> modifications;
	
	// bi-directional many-to-one association to Engagement
	@OneToMany(mappedBy = "rubriqueBudgetaire",fetch = FetchType.EAGER)
	private Set<Engagement> engagements;

	// bi-directional many-to-one association to Etablissement
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "ID_ETABLISSEMENT")
	private Etablissement etablissement;

	// bi-directional many-to-one association to ProgrammeEmploi
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "ID_PROGRAMME_EMPLOI")
	private ProgrammeEmploi programmeEmploi;

	// bi-directional many-to-one association to Rubrique
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "ID_RUBRIQUE")
	private Rubrique rubrique;

	

	public RubriqueBudgetaire() {
	}

	public int getIdRubriqueBudgetaire() {
		return this.idRubriqueBudgetaire;
	}

	public void setIdRubriqueBudgetaire(int idRubriqueBudgetaire) {
		this.idRubriqueBudgetaire = idRubriqueBudgetaire;
	}

	public BigDecimal getCreditAccordeRubriqueBudgetaire() {
		return this.creditAccordeRubriqueBudgetaire;
	}

	public void setCreditAccordeRubriqueBudgetaire(
			BigDecimal creditAccordeRubriqueBudgetaire) {
		this.creditAccordeRubriqueBudgetaire = creditAccordeRubriqueBudgetaire;
	}

	public BigDecimal getCreditFinalRubriqueBudgetaire() {
		return this.creditFinalRubriqueBudgetaire;
	}

	public void setCreditFinalRubriqueBudgetaire(
			BigDecimal creditFinalRubriqueBudgetaire) {
		this.creditFinalRubriqueBudgetaire = creditFinalRubriqueBudgetaire;
	}

	public BigDecimal getCreditReporteRubriqueBudgetaire() {
		return this.creditReporteRubriqueBudgetaire;
	}

	public void setCreditReporteRubriqueBudgetaire(
			BigDecimal creditReporteRubriqueBudgetaire) {
		this.creditReporteRubriqueBudgetaire = creditReporteRubriqueBudgetaire;
	}

	public Set<Engagement> getEngagements() {
		return this.engagements;
	}

	public void setEngagements(Set<Engagement> engagements) {
		this.engagements = engagements;
	}

	public Etablissement getEtablissement() {
		return this.etablissement;
	}

	public void setEtablissement(Etablissement etablissement) {
		this.etablissement = etablissement;
	}

	public ProgrammeEmploi getProgrammeEmploi() {
		return this.programmeEmploi;
	}

	public void setProgrammeEmploi(ProgrammeEmploi programmeEmploi) {
		this.programmeEmploi = programmeEmploi;
	}

	public Rubrique getRubrique() {
		return this.rubrique;
	}

	public void setRubrique(Rubrique rubrique) {
		this.rubrique = rubrique;
	}

		
	public BigDecimal getCreditEngagementBudgetInvest() {
		return creditEngagementBudgetInvest;
	}

	public void setCreditEngagementBudgetInvest(
			BigDecimal creditEngagementBudgetInvest) {
		this.creditEngagementBudgetInvest = creditEngagementBudgetInvest;
	}
	
	public Set<OrdreModif> getModifications() {
		return modifications;
	}

	public void setModifications(Set<OrdreModif> modifications) {
		this.modifications = modifications;
	}
	
	

	public BigDecimal getCreditEngagement() {
		return creditEngagement;
	}

	public void setCreditEngagement(BigDecimal creditEngagement) {
		this.creditEngagement = creditEngagement;
	}

	public BigDecimal getCreditPaiement() {
		return creditPaiement;
	}

	public void setCreditPaiement(BigDecimal creditPaiement) {
		this.creditPaiement = creditPaiement;
	}

	@Override
	public String toString() {
		return "Rubrique: " + this.rubrique.getNomenclatureRubrique()
				+ " Credit Accordé: " + this.creditAccordeRubriqueBudgetaire
				+ " Année Emploi:"
				+ this.programmeEmploi.getAnneeProgrammeEmploi()
				+ " Etablissement" + this.etablissement.getNomEtablissement();
	}
}